﻿using System;
using UnityEngine;


public abstract class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
{
    private static T _instance;
    protected Transform root;
    public static T Instance
    {
        get
        {
            if (_instance == null)
            {
                GameObject root = new GameObject(typeof(T).ToString());
                GameObject.DontDestroyOnLoad(root);
                _instance = root.AddComponent<T>();
                _instance.root = root.transform;
                _instance.initialize();
            }
            return _instance;
        }
    }


    protected virtual void initialize()
    {

    }

    public virtual void dispose()
    {

    }


}

